<template>
	<view class="body">
		<u-navbar
			:title="title"
			title-color="#000"
			:title-bold="true"
			:border-bottom="false"
			:background="{ background: '#ffffff' }"
			:back-icon-color="'#000'"
			:is-back="true"
		></u-navbar>

		<view class="address-section">
			<view v-if="selectedAddress && addresBoll" class="flex align-center flex-between" style="width: 100%">
				<view class="address-icon">
					<image src="/static/order/index2.png" mode="" style="width: 48rpx; height: 48rpx"></image>
				</view>
				<view class="address-content" style="font-weight: bold">
					<view class="address-title">{{ selectedAddress.name }} {{ selectedAddress.phone }}</view>
					<view class="address-tip">{{ selectedAddress.address }}</view>
				</view>
				<u-icon name="arrow-up" @click="addresBoll = false"></u-icon>
			</view>

			<view v-else class="flex align-center flex-between" style="font-weight: bold; width: 100%">
				<view class="address-icon">
					<image src="/static/order/index2.png" mode="" style="width: 38rpx; height: 38rpx"></image>
				</view>
				<view class="address-title-else">{{ selectedAddress.name }} {{ selectedAddress.phone }} {{ selectedAddress.address }}</view>
				<u-icon name="arrow-down" size="28" @click="addresBoll = true"></u-icon>
			</view>
		</view>

		<x-goods-card
			:totalNum="orders.totalNum"
			:getImgUrl="getImgUrl"
			:todayPrice="orders.price"
			:goodStars="orders.axGood ? orders.axGood.goodStars : 0"
			:goodName="orders.axGood ? orders.axGood.goodName : ''"
		></x-goods-card>

		<view class="tag">
			<view class="flex align-center flex-between mb30">
				<text>实际付款</text>
				<text>¥{{ orders.totalFee }}</text>
			</view>
			<view class="flex align-center flex-between mb30">
				<text>订单号</text>
				<text>
					{{ orders.orderNum }}
					<image @click="onCopy(orders.orderNum)" src="/static/user/Frame(1).png" class="copy" mode="aspectFill"></image>
				</text>
			</view>
			<view class="flex align-center flex-between mb30">
				<text>下单时间</text>
				<text>{{ orders.createTime }}</text>
			</view>
			<view class="flex align-center flex-between mb30">
				<text>支付信息</text>
				<text>{{ orders.receiverPhone }}</text>
			</view>
			<view class="flex align-center flex-between" v-if="title != '待发货'">
				<text>快递单号</text>
				<text>
					{{ orders.transNum }}
					<image @click="onCopy(orders.transNum)" src="/static/user/Frame(1).png" class="copy" mode="aspectFill"></image>
				</text>
			</view>
		</view>

		<view v-if="title == '待收货'">
			<view class="btn-sh" @click="setAxOrder()">收货</view>
		</view>
	</view>
</template>

<script>
import oerder from '@/api/oerder.js';
export default {
	data() {
		return {
			title: '待收货',
			addresBoll: false,
			orders: {},
			selectedAddress: {}
		};
	},
	async onLoad(o) {
		if (o.title) {
			this.title = o.title;
		}
		if (o.id) {
			await this.getAxOrder(o.id);
		}
	},
	computed: {
		getImgUrl() {
			return this.orders.axGood?.goodImg.split(',')[0] || '';
		}
	},
	methods: {
		onCopy(row) {
			wx.setClipboardData({
				data: row,
				success(res) {
					wx.showToast({
						title: '复制成功',
						icon: 'success'
					});
				}
			});
		},
		async getAxOrder(id) {
			this.loadingMore = true;
			const _this = this;
			const res = await oerder.getAxOrder(id);
			_this.orders = res.data;
			_this.selectedAddress.address = _this.orders.receiverAddress;
			_this.selectedAddress.phone = _this.orders.receiverPhone;
			_this.selectedAddress.name = _this.orders.receiverName;
			_this.loadingMore = false;
		},
		setAxOrder() {
			oerder
				.setAxOrder({
					id: this.orders.id,
					orderState: 3
				})
				.then((res) => {
					uni.showToast({
						title: '收货成功',
						icon: 'success',
						duration: 1000
					});

					setTimeout(() => {
						uni.navigateBack();
					}, 1000);
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.body {
	margin: 30rpx;
}
.btn-sh {
	height: 70rpx;
	width: 36%;
	margin: 200rpx 0;
	margin-left: 32%;
	border-radius: 100rpx;
	background-color: #25a8ff;
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
}
.tag {
	background-color: #fff;
	margin: 30rpx 0;
	padding: 30rpx;
	border-radius: 30rpx;
	.copy {
		width: 24rpx;
		height: 24rpx;
		margin-left: 10rpx;
	}
}
.address-section {
	background-color: #fff;
	padding: 30rpx;
	margin: 20rpx 0;
	position: relative;
	display: flex;
	align-items: center;
	border-radius: 30rpx;
	.address-icon {
		width: 80rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
	}
	.address-content {
		flex: 1;
		margin-right: 20rpx;

		.address-title {
			font-size: 30rpx;
			color: #333;
			margin-bottom: 10rpx;
		}

		.address-tip {
			font-size: 26rpx;
			color: #999;
		}
	}

	.address-arrow {
		width: 40rpx;
		height: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.address-arrow::after {
		content: '';
		display: block;
		width: 16rpx;
		height: 16rpx;
		border-top: 2rpx solid #999;
		border-right: 2rpx solid #999;
		transform: rotate(45deg);
	}
	.address-title-else {
		display: -webkit-box;
		-webkit-line-clamp: 1; /* 限制为两行 */
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
	}
}
</style>
